package com.supervision.parent.ui.home;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;

import com.supervision.parent.R;

public class HomeFragment extends Fragment implements View.OnClickListener {

    private HomeViewModel homeViewModel;
    private Button btnSch;
    private Button btnGra;
    private Button btnAnn;
    private LinearLayout linearLayout;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        homeViewModel =
                ViewModelProviders.of(this).get(HomeViewModel.class);
        View root = inflater.inflate(R.layout.fragment_home, container, false);
        homeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
            @Override
            public void onChanged(@Nullable String s) {
            }
        });
        btnSch = root.findViewById(R.id.btn_schedule);
        btnGra = root.findViewById(R.id.btn_grades);
        btnAnn = root.findViewById(R.id.btn_announcement);
        linearLayout = root.findViewById(R.id.home_fra);

        btnSch.setOnClickListener(this);
        btnGra.setOnClickListener(this);
        btnAnn.setOnClickListener(this);
        return root;
    }

    @Override
    public void onClick(View v) {
        linearLayout.removeAllViews();
        switch (v.getId()) {
            case R.id.btn_schedule:
                getFragmentManager().beginTransaction().addToBackStack(null)
                        .replace(R.id.home_fra, new ScheduleFragment()).commit();
                break;
            case R.id.btn_grades:
                getFragmentManager().beginTransaction().addToBackStack(null)
                        .replace(R.id.home_fra, new GradesFragment()).commit();

                break;
            case R.id.btn_announcement:
                getFragmentManager().beginTransaction().addToBackStack(null)
                        .replace(R.id.home_fra, new AnnouncementFragment()).commit();
                break;
        }
    }
}
